//
//  SampleCodeMainMenuViewController.m
//  iOS UI Sample Code
//
//  Created by 규성 이 on 12. 2. 19..
//  Copyright (c) 2012년 kkamci77@gmail.com. All rights reserved.
//

#import "SampleCodeMainMenuViewController.h"
#import "UILabelMenuViewController.h"
#import "UITextViewMenuViewController.h"
#import "UIScrollViewMenuViewController.h"
#import "UITableViewMenuViewController.h"
#import "GestureMenuViewController.h"

@implementation SampleCodeMainMenuViewController
@synthesize tvSampleCode, aListData;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self.navigationItem setTitle:@"iOS Sample Code"];
    
    [self initLoadData];
    
    [self.tvSampleCode setDataSource:self];
    [self.tvSampleCode setDelegate:self];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated{
    UIApplication * application = [UIApplication sharedApplication];
    [application setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc {
    [tvSampleCode release];
    [aListData release];
    [super dealloc];
}

#pragma init Method
- (void) initLoadData
{
    self.aListData = [[[NSArray alloc] initWithObjects:
                       MAIN_MENU_TITLE_LABEL, 
                       MAIN_MENU_TITLE_TEXTVIEW, 
                       MAIN_MENU_TITLE_SCROLLVIEW,
                       MAIN_MENU_TITLE_TABLEVIEW,
                       MAIN_MENU_TITLE_GESTURE,
                       nil] autorelease];
}

#pragma mark - Table view data source Delegate Implements
// Require Method
/**
 * 각 Section에 포함된 Row 개수를 리턴한다. 
 */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // #warning Incomplete method implementation.
    // Return the number of rows in the section.
    return [self.aListData count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"memolistCell"];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        //cell = [[[NSBundle mainBundle] loadNibNamed:@"memolistCell" owner:self options:nil] lastObject];
    }
    
//    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    // Configure the cell...
    cell.textLabel.text = [self.aListData objectAtIndex:indexPath.row];
//    UILabel * label = (UILabel *)[cell viewWithTag:2];
//    [label setText:((MemoData *)[self.listData objectAtIndex:[indexPath row]]).name];
//    
//    UIImageView * imView = (UIImageView *)[cell viewWithTag:1];
//    [imView setImage:[((MemoData *)[self.listData objectAtIndex:[indexPath row]]) getThumbnailImage]];
//    
//    UILabel * lblDate = (UILabel *)[cell viewWithTag:3];
//    [lblDate setText:[((MemoData *)[self.listData objectAtIndex:[indexPath row]]).createDate description]];
    return cell;
}

// Optional Method
/*
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // #warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1; // [self.sectionData count];
}
*/
/**
 * - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
 * 이 Method를 구현하면 자동으로 Swife하여 Delete 버튼이 표시되게 된다.
 */
/*
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(editingStyle == UITableViewCellEditingStyleDelete)
    {
        NSLog(@"Delete EditStyle = %d", editingStyle);
    }
    else if(editingStyle == UITableViewCellEditingStyleInsert)
    {
        NSLog(@"Edit Style is Insert");
    }else
    {
        NSLog(@"Edit Style is None");
    }
}
*/
/*
 // Override to support conditional editing of the table view.
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
 {
 // Return NO if you do not want the specified item to be editable.
 return YES;
 }
*/

#pragma UITableViewDelegate Implements
/*
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
*/
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case MAIN_MENU_TITLE_LABEL_INDEX:
        {
            UILabelMenuViewController * uilabelMenuViewController = [[UILabelMenuViewController alloc] initWithNibName:@"UILabelMenuViewController" bundle:nil];
            [self.navigationController pushViewController:uilabelMenuViewController animated:YES];
            [uilabelMenuViewController release];
        }
            break;
        case MAIN_MENU_TITLE_TEXTVIEW_INDEX:
        {
            UITextViewMenuViewController * uiTextViewMenuViewController = [[UITextViewMenuViewController alloc] initWithNibName:@"UITextViewMenuViewController" bundle:nil];
            [self.navigationController pushViewController:uiTextViewMenuViewController animated:YES];
            [uiTextViewMenuViewController release];
        }
            break;
        case MAIN_MENU_TITLE_SCROLLVIEW_INDEX:
        {
            UIScrollViewMenuViewController * uiScrollViewMenuViewController = [[UIScrollViewMenuViewController alloc] initWithNibName:@"UIScrollViewMenuViewController" bundle:nil];
            [self.navigationController pushViewController:uiScrollViewMenuViewController animated:YES];
            [uiScrollViewMenuViewController release];
        }
            break;
        case MAIN_MENU_TITLE_TABLEVIEW_INDEX:
        {
            UITableViewMenuViewController * uiTableViewMenuViewController = [[UITableViewMenuViewController alloc] initWithNibName:@"UITableViewMenuViewController" bundle:nil];
            [self.navigationController pushViewController:uiTableViewMenuViewController animated:YES];
            [uiTableViewMenuViewController release];
        }
            break;
        case MAIN_MENU_TITLE_GESTURE_INDEX:
        {
            GestureMenuViewController * gestureMenuViewController = [[GestureMenuViewController alloc] initWithNibName:@"GestureMenuViewController" bundle:nil];
            [self.navigationController pushViewController:gestureMenuViewController animated:YES];
            [gestureMenuViewController release];
        }
            break;
        default:
            break;
    }
}
/*
- (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
*/
/*
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
*/
@end
